#include <QAbstractTableModel>
#include "TreeItem.h"
//#include "configsetting.h"
//#include "datacache.h"

//class TreeItem;
class TreeModel : public QAbstractItemModel
{
    Q_OBJECT
    enum ItemRoles {
        Role1 = Qt::UserRole + 1,
        Role2,
        Role3,
        Role4,
        Role5,
        Role6,
        Role7,
        Role8,
        Role9
    };
public:
    TreeModel(QObject *parent = NULL);
    ~TreeModel();


    void appendChild(const QModelIndex& index);
    bool removeRows(int row, int count, QModelIndex parent);

    Q_INVOKABLE virtual QVariant headerData(int section, Qt::Orientation orientation,
                                int role = Qt::DisplayRole) const;
    QModelIndex parent(const QModelIndex &index) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    QVariant data(const QModelIndex &index, int role) const;
    QHash<int, QByteArray> roleNames() const;

    //返回，0循环层，1工步层，其它值为记录层
//    Q_INVOKABLE int getRowType(const QModelIndex &index);
    //是否为叶子节点
    Q_INVOKABLE bool isLeafNode(const QModelIndex &index);

    void AppendTreeData(TreeItem* pTreeData);
    QVariant GetNodeText(const QModelIndex &index);

    void SetRole(int nIndex, QByteArray qByteAr);
protected:

private:
    TreeItem *m_rootItem;
    QHash<int,QByteArray> m_roleNames;
    int         m_nCoumnCount;
//    ConfigSetting m_Cfg;    //只用于读取配置
};
